package com.zb.exceptions;

import com.zb.enums.ResultTypeEnum;
import com.zb.util.ResultResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice  //异常处理
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    @ResponseBody
    public ResultResponse handleExcepting(BusinessException e) {
        log.error(e.getMessage());
        return ResultResponse.error(e.resultTypeEnum);
    }

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResultResponse handleExcepting(Exception e) {
        log.error(e.getMessage());
        return ResultResponse.error(ResultTypeEnum.SERVICE_ERROR);
    }

}
